<template>
  <view class="content">
    <image mode="widthFix" :src="$util.getAppLogo()" />
    <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" scope="phoneNumber">
      授权登录
    </button>
  </view>
</template>
<script>
export default {
  data() {
    return {
      openid: "",
    };
  },
  onShareAppMessage() {
    return this.$util.returnShareObj();
  },
  onLoad(options) {
    this.openid = options.openid;
    setTimeout(() => {
      uni.hideHomeButton();
    }, 100);
  },
  methods: {
    getPhoneNumber(e) {
      if (e.detail.errMsg == "getPhoneNumber:ok") {
		let data={
            code: e.detail.code,
            openId: this.openid,
          }
		 if(uni.getStorageSync('doctorId')) {
			data.doctorId=uni.getStorageSync('doctorId')
		 }
        this.$api
          .loginByPhoneAndBind(data)
          .then((res) => {
            if (res.code == 200 && res.data.token) {
              uni.setStorage({
                key: "token",
                data: res.data.token,
                success: () => {
                  uni.reLaunch({
                    url: "/pages/index/index",
                  });
                },
              });
            } else {
              this.$util.showToast("授权登录失败，请重试");
            }
          });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  background: #fff;
  image {
    width: 400rpx;
    height: 400rpx;
    margin: 100rpx 0 0 175rpx;
  }
  .btn {
    width: 70vw;
    background: $theme-color;
    color: #fff;
  }
}
</style>
